package com.cxp.tour.common;

import com.cxp.tour.entity.Scenic;
import lombok.Data;
import org.springframework.http.ResponseEntity;

import java.util.List;

@Data
public class Result {
    //后端返回数据封装
    private int code;   //编码 200(成功)/400(失败)
    private String msg; //成功/失败
    private Long total; //总记录数
    private Object data; //数据（不确定类型直接用Object）

    //失败
    public static Result fail(){
        return result(400,"失败",0L,null);
    }
    public static Result fail(Object data){
        return result(400,"失败",0L,data);
    }
//    public static Result fail(Object data){
//        return result(400,"失败",0L,data);
//    }

    //成功
    public static Result suc(){
        return result(200,"成功",0L,null);
    }
    //成功
    public static Result suc(Object data){
        return result(200,"成功",0L,data);
    }
    //成功
    public static Result suc(Object data,Long total){
        return result(200,"成功",total,data);
    }


    private static Result result(int code,String msg,Long total,Object data){
        Result res = new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        return res;
    }

}
